//
//  def_selection_statement.h
//  compilation
//
//  Created by Kevin Le perf on 17/01/12.
//  Copyright (c) 2012 e2co technologie. All rights reserved.
//

#ifndef compilation_def_selection_statement_h
#define compilation_def_selection_statement_h

/*
 selection_statement
 : IF '(' expression ')' statement {printf("selection_statement\n");}
 | IF '(' expression ')' statement ELSE statement {printf("selection_statement\n");}
 | FOR '(' expression_statement expression_statement expression ')' statement {printf("selection_statement\n");}
 ; 
 */

struct def_selection_statement{
	void * parent;
	int type;
	struct def_expression * expression;
	struct def_statement * statement;
	struct def_statement * statement_2;
	struct def_expression_statement * expression_statement;
	struct def_expression_statement * expression_statement_2;	
};

struct def_selection_statement * selection_statement_create(void * parent){
	struct def_selection_statement * s = malloc(sizeof(*s));
	s->type = 0;
	s->parent = parent;
	return s;
}

void selection_statement_print(struct def_selection_statement * s){
	switch(s->type){
		case 1:
			printf("if(");
			expression_print(s->expression);
			printf(")");
			statement_print(s->statement);
			break;
		case 2:
			printf("if(");
			expression_print(s->expression);
			printf(")");
			statement_print(s->statement);
			printf("else");
			statement_print(s->statement_2);
			break;
		case 3:
			printf("for(");
			expression_statement_print(s->expression_statement);
			expression_statement_print(s->expression_statement_2);
			expression_print(s->expression);
			printf(")");
			statement_print(s->statement);
	}
}
#endif
